package cn.enilu.flash.dao.park;


import cn.enilu.flash.bean.entity.park.ParkingQuoteRef;
import cn.enilu.flash.dao.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

public interface ParkingQuoteRefRepository extends BaseRepository<ParkingQuoteRef,Long>{

    @Query(nativeQuery = true, value = "select \n" +
            "\ta.id,a.quote_type as quoteType, a.quote_range as quoteRange, a.quote_unit as quoteUnit, a.quote_price as quotePrice,\n" +
            "\tcase when b.id is null then 0 else 1 end  as checked1, \n" +
            "\tcase when c.id is null then 0 else 1 end  as checked2, c.start_date as startDate, c.end_date as endDate\n" +
            "from parking_quote a \n" +
            "left join parking_quote_ref b on a.id=b.quote_id and b.parking_id=?2\n" +
            "left join parking_contract c on a.id=c.quote_id and c.parking_id=?2\n" +
            "where a.community_id=?1")
    List<Map<String, Object>> getAllQuotes(Long communityId, Long parkingId);

    @Modifying
    @Query(nativeQuery = true,value = "delete from parking_quote_ref where parking_id=?1")
    void deleteByParkingId(Long parkingId);
}

